package com.example.gallery;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class ImageActivity extends Activity
{
	//멀티터치 대응
	enum TouchMode{
		NONE,DRAG,ZOOM
	};
	TouchMode tMode = TouchMode.NONE;
	//드래그 좌표 저장
	float posX1 = 0, posX2 = 0, posY1 = 0 , posY2 = 0;
	
	float newDist = 1f;
	
	String rootPath;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Intent intent = getIntent();
		rootPath = intent.getStringExtra("assetsPath");
//		
		Bitmap bitmap = Util.getBitmapFromAssets(this, rootPath);
//		
//		imageView.setImageBitmap(bitmap);
//		imageView.setScaleType(ScaleType.MATRIX);
//		
//		imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
////		imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
//		imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
//			
//			@Override
//			public boolean onPreDraw() {
//				// TODO Auto-generated method stub
////				imageView.getViewTreeObserver().removeOnPreDrawListener(this);
////				newMatrix.setTranslate(imageView.getWidth()/2-bitmapWidth/2, imageView.getHeight()/2 - bitmapHeight/2);
////				imageView.setImageMatrix(newMatrix);
//				
//				int rectX = (imageView.getWidth() - bitmapWidth)/2;
//				int rectY = (imageView.getHeight() - bitmapHeight)/2;
//				
//				RectF viewRect = new RectF(rectX,rectY,rectX + bitmapWidth, rectY + bitmapHeight);
//				RectF bitmapRect = new RectF(0,0,bitmapWidth,bitmapHeight);
//				
//				Matrix matrix = new Matrix();
//				
//				matrix.setRectToRect(bitmapRect,viewRect, Matrix.ScaleToFit.CENTER);
//				imageView.setImageMatrix(matrix);
//				return true;
//			}
//		});
//		
//		Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
//		DisplayMetrics dm = new DisplayMetrics();
//		getWindowManager().getDefaultDisplay().getMetrics(dm);
//		
//		displayWidth = display.getWidth();
//		displayHeight = display.getHeight();
//		
		
		ImageViewEx ive = new ImageViewEx(this);
		ive.setImageBitmap(bitmap);
		
		
		RelativeLayout rLayout = new RelativeLayout(this);
		rLayout.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
		rLayout.addView(ive,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
		
		setContentView(rLayout);
		

	}


	
}